#include<bits/stdc++.h>
using namespace std;
int t,n,a[200001];
long long f[200001][2];
long long dfs(int i,int b,int r,long long s){
    if (i==n+1) return s;
    long long x;
    if (a[i]==a[b]) x=dfs(i+1,i,r,s+a[i]);
    else x=dfs(i+1,i,r,s);
    if (a[i]==a[r]) x=max(x,dfs(i+1,b,i,s+a[i]));
    else x=max(x,dfs(i+1,b,i,s));
    return x;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&t);
    for (;t;t--){
        scanf("%d",&n);
        for (int i=1;i<=n;i++) scanf("%d",&a[i]);
        printf("%lld\n",dfs(1,0,0,0LL));
    }
    return 0;
}
